<template>
  <a-modal
    :maskClosable="maskClosable"
    title="动态电压调频策略设置"
    :width="800"
    :visible="visible"
    :confirm-loading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-form-item label="动态电压调频策略">
          <a-radio-group v-model="model.voltageFmStrategy">
            <a-radio v-for="(d, i) in model.supportStrategies" :key="i" :value="d"> {{ d }} </a-radio>
          </a-radio-group>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
<script>
import { gPostAction } from '@/api/manage'
export default {
  name: 'ConfigModal',
  data() {
    return {
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this),
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
      radioStyle: {},
      maskClosable: false,
    }
  },
  methods: {
    config(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    handleOk(e) {
      this.confirmLoading = true
      const postData = {
        id: this.model.id,
        voltageFmStrategy: this.model.voltageFmStrategy,
      }

      gPostAction('/fm/setStrategy', postData)
        .then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
            this.$emit('ok')
          }
        })
        .finally(() => {
          this.confirmLoading = false
          this.handleCancel()
        })
    },
    handleCancel(e) {
      this.visible = false
    },
  },
}
</script>
